// Shadows
$shadow_0: 0 1px 2px 0 rgba(0, 0, 0, 0.1), 0 2px 2px 0 rgba(0, 0, 0, 0.05);  // Slider hover shadow
$shadow_1: 0 1px 1px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.06); // Header-button shadow
$shadow_2: 0 1px 1px 0 rgba(16, 16, 16, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.05);  // Slider normal shadow
$shadow_3: 0 1px 1px 0 rgba(0, 0, 0, 0.03);                                     // Normal button shadow
$shadow_4: 0 2px 3px 0 rgba(0, 0, 0, 0.2), 0 3px 5px 0 rgba(0, 0, 0, 0.15);  // Switch-slider hover shadow
$shadow_5: 0 1px 2px 0 rgba(0, 0, 0, 0.15), 0 2px 3px 0 rgba(0, 0, 0, 0.1);  // Switch-slider normal shadow
$text_shadow: 0 -1px rgba(#ffffff, 0.04), -1px 0 rgba(0, 0, 0, 0.05), 1px 0 rgba(0, 0, 0, 0.05),
              0 1px rgba(0, 0, 0, 0.3), 0 2px rgba(0, 0, 0, 0.05); // text and icon shadow

// Transitions
$ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$transition_1: all 0.2s cubic-bezier(0, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0, 0, 0.2, 1);
$transition_2: all 0.1s cubic-bezier(0, 0, 0.2, 1);
$shadow_transition: box-shadow 0.2s cubic-bezier(0, 0, 0.2, 1);
$button_transition: all 100ms $ease-out-quad;
$backdrop_transition: 200ms ease-out;

// Images
$button_active_image: linear-gradient(0deg, $button_active_bottom 0%, $button_active_top 100%);
$button_active_hover_image: linear-gradient(0deg, $button_active_hover_bottom 0%, $button_active_hover_top 100%);

$headerbar_bg_image: linear-gradient(0deg, $header_bottom 0%, $header_middle 50%, $header_top 100%);
$headerbar_top_image: linear-gradient(0deg, $header_middle 0%, $header_top 100%);
$header_button_image: if($variant=='light', linear-gradient( 0deg, #f1f1f1 0%, #fdfdfd 95%, #fefefe 100%),
                                            linear-gradient( 0deg, #636363 0%, #696969 100%));
$header_button_hover_image: if($variant=='light', linear-gradient( 0deg, #f8f8f8 0%, #ffffff 100%),
                                                  linear-gradient( 0deg, #707070 0%, #767676 100%));
$header_button_checked_image: if($variant=='light', linear-gradient( 0deg, #656565 0%, #707070 100%),
                                                    linear-gradient( 0deg, #c1c1c1 0%, #c6c6c6 100%));

$menubar_bg_image: linear-gradient(0deg, $header_bottom 0%, $header_middle 100%);

// Animations
$switch_animation: switch_ripple_effect 0.3s cubic-bezier(0, 0, 0.2, 1);

@keyframes switch_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $success_color 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $success_color 100%,
                                      transparent 0%);
  }
}

@keyframes header_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 100%,
                                      transparent 0%);
  }
}

// Drawing mixins

// Solid color image
@function _solid($c) {
  @return linear-gradient(to bottom, $c, $c);
}

// Entries

@mixin entry($t) {
//
// Entries drawing function
//
// $t: entry type
//

  @if $t==normal {
  //
  // normal entry
  //
    color: $text_color;
    // border-color: $entry_border;
    // border-bottom-color: $entry_bottom_border;
    background-color: $entry_bg;
  }

  @if $t==focus {
  //
  // focused entry
  //
    color: $text_color;
    // border-color: $entry_highlight;
    background-color: $entry_bg;
  }

  @if $t==insensitive {
  //
  // insensitive entry
  //
    color: $insensitive_fg_color;
    // border-color: $entry_border;
    background-color: rgba($entry_bg, 0.55);
  }

  @if $t==header-normal {
  //
  // normal header-bar entry
  //
    color: $header_fg;
    // border-bottom-color: $entry_border;
    background-color: $header_button_bg;
    background-image: $header_button_image;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px $header_button_highlight;
    }

    image, image:hover { color: inherit; }
  }

  @if $t==header-focus {
  //
  // focused header-bar entry
  //
    // border-color: $selection_mode_bg;
    background-image: none;
    background-color: $entry_bg;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px transparent;
    }
  }

  @if $t==header-insensitive {
  //
  // insensitive header-bar entry
  //
    color: rgba($header_fg, 0.35);
    background-color: $header_button_bg;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px $header_button_highlight;
    }
  }

  @else if $t==osd {
  //
  // normal osd entry
  //
    color: $osd_fg_color;
    border-color: $osd_entry_border;
    background-color: $osd_entry_bg;

    image, image:hover { color: inherit; }
  }

  @else if $t==osd-focus {
  //
  // active osd entry
  //
    color: $selected_fg_color;
    border-color: darken($selection_mode_bg, 5%);
    background-color: $selected_bg_color;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd entry
  //
    color: $osd_fg_color;
    background-color: transparentize($osd_entry_bg, 0.15);
  }
}

// Buttons

@mixin button($t, $actionb_bg:red, $actionb_fg: green) {
//
// Button drawing function
//
// $t:    button type,
// $actionb_bg, $actionb_fg: used for destructive and suggested action buttons

  @if $t==normal {
  //
  // normal button
  //
    color: $fg_color;
    border-color: $button_borders;
    border-top-color: $button_borders_top;
    border-bottom-color: $button_borders_bottom;
    background-color: $button_bg;
    @if $variant=='light' { box-shadow: $shadow_3; }
    @if $variant=='dark' {
      box-shadow: inset 0 1px $button_highlight, $shadow_3;
    }
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: if($variant == 'light', darken($fg_color, 10%), lighten($fg_color, 10%));
    border-color: $button_borders_hover;
    border-top-color: $button_borders_hover_top;
    border-bottom-color: $button_borders_hover_bottom;
    background-color: if($variant=='light', darken($button_bg, 3%), lighten($button_bg, 3%));
    @if $variant=='light' { box-shadow: none; }
    @if $variant=='dark' {
      box-shadow: inset 0 1px rgba($button_highlight, 0.12), $shadow_3;
    }
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $selected_fg_color;
    background-color: $selected_bg_color;
    border-color: $button_borders_active;
    border-top-color: $button_borders_active_top;
    border-bottom-color: $button_borders_active_bottom;
    background-image: $button_active_image;
    @if $variant=='light' { box-shadow: none; }
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    label, & { color: $insensitive_fg_color; }

    border-color: if($variant == 'light', $button_border, $dark_borders_color);
    background-color: rgba($button_bg, 0.55);
    @if $variant=='light' { box-shadow: $shadow_3; }
  }

  @else if $t==insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.45); }

    border-color: if($variant == 'light', transparentize($selected_bg_color, 0.25), $dark_borders_color);
    background-color: transparentize($selected_bg_color, 0.45);
    @if $variant=='light' { box-shadow: none; }

    opacity: 0.6;
  }

  @if $t==flat-normal {
  //
  // normal button
  //
    border: none;
    background-color: transparent;
    box-shadow: none;
    background-clip: if($variant=='light', border-box, padding-box);
  }

  @else if $t==flat-hover {
  //
  // hovered button
  //
    color: darken($fg_color, 10%);
    background-color: if($variant=='light', rgba(black, 0.15), rgba(white, 0.15));
    background-image: none;
    // border-color: if($variant=='light', rgba(black, 0.15), rgba(white, 0.15));
  }

  @else if $t==flat-active {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.5), rgba(white, 0.25));
  }

  @else if $t==flat-checked {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.65), rgba(white, 0.35));
  }

  @else if $t==flat-insensitive {
  //
  // insensitive button
  //
    label, & { color: $insensitive_fg_color; }

    background-color: transparent;
//    border: none;
  }

  @else if $t==flat-insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.2); }

    background-color: lighten($fg_color, 20%);
    opacity: 0.6;
  }

  @if $t==header-normal {
  //
  // normal header-bar button
  //
    border-color: $borders_color;
    color: $header_fg;
    background-color: $header_button_bg;
    background-image: $header_button_image;

    @if $variant == 'dark' {
      border: none;
      box-shadow: inset 0 1px $header_button_highlight;
    }
  }

  @else if $t==header-hover {
  //
  // hovered header-bar button
  //
    border-color: $borders_color;
    color: darken($header_fg, 2%);
    background-color: $header_button_hover_bg;
    background-image: $header_button_hover_image;
    @if $variant == 'dark' { box-shadow: inset 0 1px $header_button_hover_highlight; }
  }

  @else if $t==header-active {
  //
  // pushed header-bar button
  //
    color: $selected_fg_color;
    background-color: $header_button_active_bg;
    background-image: none;
    border-color: $borders_color;
  }

  @else if $t==header-checked {
  //
  // pushed header-bar button
  //
    color: if($variant=='light', $selected_fg_color, $alt_fg_color);
    background-color: $header_button_checked_bg;
    background-image: $header_button_checked_image;
    border-color: $borders_color;
    @if $variant == 'dark' { box-shadow: inset 0 1px $header_button_checked_highlight; }
  }

  @else if $t==header-insensitive {
  //
  // insensitive header-bar button
  //
    label, & { color: rgba($header_fg, 0.35); }
    background-color: $header_button_bg;

    @if $variant == 'dark' { box-shadow: inset 0 1px $header_button_highlight; }
  }

  @else if $t==header-insensitive-active {
  //
  // header-bar insensitive pushed button
  //
    color: rgba($selected_fg_color, 0.35);
    background-color: rgba($header_button_active_bg, 0.55);
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: $osd_button_bg;
    box-shadow: none;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: opacify(lighten($osd_button_bg, 7%), 0.1);
    box-shadow: none;
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border-color: if($variant == 'light', $selected_bg_color, $osd_button_border);
    background-color: $selected_bg_color;
    background-image: none;
    box-shadow: none;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    color: $osd_insensitive_fg_color;
    border-color: $osd_button_border;
    background-color: transparentize($osd_button_bg, 0.15);
    box-shadow: none;
  }

  @else if $t==suggested_destructive {
  //
  // suggested or destructive action buttons
  //
    @if $variant == 'light' { background-clip: border-box; }

    color: $actionb_fg;
    background-color: $actionb_bg;
    border-color: if($variant == 'light', darken($actionb_bg, 6%), $dark_borders_color);
    background-image: none;
//    box-shadow: none;
  }

  @else if $t==undecorated {
  //
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
  }
}

//
// Overshoot
//
@mixin overshoot($p, $c:$selected_bg_color) {
// $p: position
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//

  $_big_gradient_length: 60%;

  $_position: center top;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==bottom {
    $_position: center bottom;
  }

  @else if $p==right {
    $_position: right center;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  @else if $p==left {
    $_position: left center;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  background-image: -gtk-gradient(radial,
                                $_position, 0,
                                $_position, 0.6,
                                from(transparentize($c, 0.8)),
                                to(transparentize($c, 1)));

  background-size: $_big_gradient_size;
  background-repeat: no-repeat;
  background-position: $_position;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

//
// Undershoot
//
@mixin undershoot($p) {
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_undershoot_color_dark: transparentize(black, 0.8);
  $_undershoot_color_light: transparentize(white, 0.8);

  $_gradient_dir: left;
  $_dash_bg_size: 10px 1px;
  $_gradient_repeat: repeat-x;
  $_bg_pos: center $p;

  background-color: transparent; // shouldn't be needed, but better to be sure;

  @if ($p == left) or ($p == right) {
    $_gradient_dir: top;
    $_dash_bg_size: 1px 10px;
    $_gradient_repeat: repeat-y;
    $_bg_pos: $p center;
  }

  background-image: linear-gradient(to $_gradient_dir, // this is the dashed line
                                    $_undershoot_color_light 50%,
                                    $_undershoot_color_dark 50%);

  padding-#{$p}: 1px;
  background-size: $_dash_bg_size;
  background-repeat: $_gradient_repeat;
  background-origin: content-box;
  background-position: $_bg_pos;
  border: none;
}
